package com.hancai.barrage.utils;

import com.hancai.barrage.model.LoginInfo;
import com.hancai.barrage.pojo.Employee;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 涵菜
 * @version 1.0
 * token管理类
 * 并发编程-JUC java.util.concurrent
 * ConcurrentHashMap保障线程安全问题
 */
abstract public class TokenManager {
    public static final String TOKEN_NAME="X-Token";
    private static final Map<String, LoginInfo> TOKEN_MAP=new ConcurrentHashMap<>();


    public static String getToken(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }
    public static void setInfo(String token,LoginInfo employee){
        TOKEN_MAP.put(token,employee);
    }
    public static LoginInfo getInfo(String token){
        return TOKEN_MAP.get(token);
    }

    public static void removeInfo(String token) {
        TOKEN_MAP.remove(token);
    }
}
